﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using FrameWorkMain;

public partial class Modules_Purchase_ucPurchaseRequestInbox : System.Web.UI.UserControl
{
    FrameWorkMain.FrameWorkMain inbox = new FrameWorkMain.FrameWorkMain();
    Purchase.Purchase purchase = new Purchase.Purchase();
    string controlPath = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {

      

        //PostBackOptions oPostOptions = new PostBackOptions(uc);
        //oPostOptions.ClientSubmit = true;
        //oPostOptions.ActionUrl = "~/a.ascx";
        //oPostOptions.PerformValidation = true;
        //oPostOptions.AutoPostBack = true;

        if (!IsPostBack)
        {
            Session.Clear();
            DataSet purchaseReqDS = inbox.GetInboxDetails();
            grvProductDetails.DataSource = purchaseReqDS;
            grvProductDetails.DataBind();
           //DataSet purchaseReqDS= purchase.GetPurchaseRequest();
           //grvProductDetails.DataSource = purchaseReqDS;
           // grvProductDetails.DataBind();
        }

        //if (Session["popupControl"] != null)
        //{
        //    controlPath = Session["popupControl"].ToString();
        //    UserControl uc = (UserControl)Page.LoadControl(Session["popupControl"].ToString());
        //    pnlPurchase.Controls.Add(uc);
        //    updPurchase.Update();
        //    mpePerson.Show();
        //}
    }

    private string LastLoadedControl
    {
        get
        {
            return ViewState["LastLoaded"] as string;
        }
        set
        {
            ViewState["LastLoaded"] = value;
        }
    }

    private void LoadUserControl()
    {
        string controlPath = "~/Modules/Purchase/ucPurchaseOrderRequest.ascx";// LastLoadedControl;

        if (!string.IsNullOrEmpty(controlPath))
        {
            UserControl uc = (UserControl)LoadControl(controlPath);
            Type ucType=uc.GetType();
            ucLoadUserControl.Controls.Add(uc);
           // pnlPurchase.Controls.Add(uc);
           //updPurchase.Update();
           // mpePerson.Show();
           // Session["popupControl"] = controlPath;

        }
    }
    protected void grvProductDetails_SelectedIndexChanged(object sender, EventArgs e)
    {
        GridViewRow row = grvProductDetails.SelectedRow;
        string a = ((Label)row.FindControl("lblRecordNumber")).Text;
        string b = ((Label)row.FindControl("lblRequestTypeId")).Text;
        string c = ((Label)row.FindControl("lblRequestLink")).Text;  

    }
    protected void btnEditPurchase_Click(object sender, EventArgs e)
    {
        ImageButton btnEdit = sender as ImageButton;
        GridViewRow row = (GridViewRow)btnEdit.NamingContainer;
      //  string controlPath = "~/Modules/Purchase/ucPurchaseOrderRequest.ascx";
        LoadUserControl();
        //UserControl uc = (UserControl)LoadControl(controlPath);
        //pnlPurchase.Controls.Add(uc);
        //updPurchase.Update();
        //mpePerson.Show();


       // txtRequester.Text = row.Cells[0].Text;
      //  txtReqDate.Text = row.Cells[1].Text;
      //  txtReqType.Text = row.Cells[2].Text;
      //  txtReqNote.Text = row.Cells[3].Text;
       // updPurchase.Update();
       // mpePerson.Show();
       
    }
    protected void lbStatus_Click(object sender, EventArgs e)
    {
        //LinkButton ProductIdButton = sender as LinkButton;
        //int uniqId = Convert.ToInt32(ProductIdButton.CommandArgument);
        //GridViewRow row = (GridViewRow)ProductIdButton.NamingContainer;
        //txtRequester.Text = row.Cells[0].Text;
        //txtReqDate.Text = row.Cells[1].Text;
        //txtReqType.Text = row.Cells[2].Text;
        //txtReqNote.Text = row.Cells[3].Text;
        //updPurchase.Update();
        //mpePerson.Show();

      //  LinkButton ProductIdButton = sender as LinkButton;
       // int uniqId = Convert.ToInt32(ProductIdButton.CommandArgument);
    }
   
    protected void btnSavePerson_Click(object sender, EventArgs e)
    {
    }
    
    protected void grvProductDetails_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string editIndex = e.Row.DataItemIndex.ToString();

            ImageButton btn = e.Row.FindControl("btnEdit") as ImageButton;
            if (btn != null) { btn.CommandArgument = editIndex; }
            btn = e.Row.FindControl("btnDelete") as ImageButton;
            if (btn != null) { btn.CommandArgument = editIndex; }
        }
    }

}
